package com.java3_8;

import java.awt.desktop.PreferencesEvent;
import java.util.concurrent.locks.ReentrantLock;

public class Demo5 {
    private String name;
    private int age;

    private Demo5(String name, int age) {
        this.name = name;
        this.age = age;
    }

    private static Demo5 demo5 = null;

    //记得使用private static修饰
    private static final ReentrantLock reentrantLock = new ReentrantLock();

    public static Demo5 getDemo5(){
        if(demo5 == null){
            try {
                reentrantLock.lock();
                demo5 = new Demo5("zhaoliu", 24);
            } catch (Exception e) {
                reentrantLock.unlock();
            }
        }
        return demo5;
    }
}
